using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace cb0tServer
{
    class OtherLogs
    {
        public static void WriteCacheLog(String text)
        {
            StreamWriter s;

            try
            {
                if (!File.Exists(sb0t_winGUI.RunOnceFileUpdater.sbotpath + "data/cachelog.txt"))
                {
                    s = File.CreateText(sb0t_winGUI.RunOnceFileUpdater.sbotpath + "data/cachelog.txt");
                }
                else
                {
                    s = File.AppendText(sb0t_winGUI.RunOnceFileUpdater.sbotpath + "data/cachelog.txt");
                }

                s.WriteLine(TimeString() + " " + text);
                s.Flush();
                s.Close();
            }
            catch { }
        }

        public static void WriteChatLog(String text)
        {
            StreamWriter s;
            String filename = DateString() + ".txt";

            try
            {
                if (!File.Exists(sb0t_winGUI.RunOnceFileUpdater.sbotpath + "chatlogs/" + filename))
                {
                    s = File.CreateText(sb0t_winGUI.RunOnceFileUpdater.sbotpath + "chatlogs/" + filename);
                }
                else
                {
                    s = File.AppendText(sb0t_winGUI.RunOnceFileUpdater.sbotpath + "chatlogs/" + filename);
                }

                s.WriteLine(TimeString() + " " + text);
                s.Flush();
                s.Close();
            }
            catch { }
        }

        private static String DateString()
        {
            DateTime d = DateTime.Now;
            StringBuilder s = new StringBuilder();
            s.Append((d.Month < 10 ? ("0" + d.Month) : d.Month.ToString()) + " ");
            s.Append((d.Day < 10 ? ("0" + d.Day) : d.Day.ToString()) + " ");
            s.Append(d.Year);
            return s.ToString();
        }

        private static String TimeString()
        {
            DateTime d = DateTime.Now;
            return d.ToShortTimeString();
        }
    }
}
